package com.BinLog.listen;

import com.alibaba.fastjson.JSONObject;
import com.github.shyiko.mysql.binlog.BinaryLogClient;
import com.github.shyiko.mysql.binlog.event.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.sql.*;
import java.util.BitSet;
import java.util.List;

@Component
@Slf4j
public class ListenBinLog implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
//        BinaryLogClient client = new BinaryLogClient("127.0.0.1", 3306, "fzys", "root", "123456");
//        client.setServerId(2);
//        client.registerEventListener(event -> {
//            EventData data = event.getData();
//            if (data instanceof UpdateRowsEventData) {
//                UpdateRowsEventData updateRowsEventData = (UpdateRowsEventData) data;
//                log.info(updateRowsEventData.toString());
//            }
//            if (data instanceof WriteRowsEventData) {
//                WriteRowsEventData writeRowsEventData = (WriteRowsEventData) data;
//                log.info(writeRowsEventData.toString());
//            }
//        });
//        client.connect();
    }
}
